package com.itheima.ydd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.ydd.common.BusinessException;
import com.itheima.ydd.entity.Cate;
import com.itheima.ydd.mapper.CateMapper;
import com.itheima.ydd.service.CateService;
import org.springframework.stereotype.Service;

@Service
public class CateServiceImpl extends ServiceImpl<CateMapper, Cate> implements CateService {
    @Override
    public void save1(Cate cate) {
        String catename = cate.getCatename();
        LambdaQueryWrapper<Cate> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(Cate::getCatename,catename);
        int count = this.count(queryWrapper
        );
        if (count>0){
            throw new BusinessException("分类名称已存在，请换个名字继续添加");
        }
        this.save(cate);
    }

//    @Override
//    public void update(Cate cate) {
//        String catename = cate.getCatename();
//        LambdaQueryWrapper<Cate> wrapper=new LambdaQueryWrapper<>();
//        wrapper.eq(Cate::getCatename,catename);
//        int count = this.count(wrapper);
//        if (count>0){
//            throw new BusinessException("分类名称已存在,请换个名字继续修改");
//        }
//        this.updateById(cate);
//    }
}
